package cn.cheniy.swiftmark.common.database.util;

import cn.cheniy.swiftmark.common.database.dto.PageDTO;

/**
 * @author cheniy
 * @description 通过计算limit来进行获得分页【根据当前页数，计算开始下标，和PageUtil功能重复】
 *  
 */
public class PageAdapter {

    private int begin;

    private int size;

    /**
     * 传入PageDTO来计算limit
     * @param page
     */
    public PageAdapter(PageDTO page) {
        this.begin = getStart(page.getPageNum() - 1, page.getPageSize());
        this.size = page.getPageSize();
    }

    public int getBegin() {
        return begin;
    }

    public void setBegin(int begin) {
        this.begin = begin;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public static int getStart(int pageNo, int pageSize) {
        if (pageNo < 0) {
            pageNo = 0;
        }

        if (pageSize < 1) {
            pageSize = 0;
        }

        return pageNo * pageSize;
    }

}
